package com.takeshi.landlords.entity;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.takeshi.landlords.util.CardModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

/**
 * PlayHistoryObj
 *
 * @author Nanase Takeshi
 * @date 2022/2/21 16:07
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class PlayHistoryObj implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 出牌人
     */
    private String nickname;

    /**
     * 牌型
     */
    private CardModel cardModel;

    /**
     * 牌
     */
    private List<String> cardList;

    /**
     * 出牌时间
     */
    private Long createTime;

    public String passPlay(String nextPlayerNickname) {
        return StrUtil.format("[{}] player PASS, please next player [{}] to play~", this.nickname, nextPlayerNickname);
    }

    public String playInfo(String nextPlayerNickname, Integer cardsCount) {
        String str = CollUtil.isEmpty(this.cardList) ? "PASS" : this.cardList.stream().map(item -> StrUtil.equals("0", item) ? "10" : item.toUpperCase(Locale.ROOT)).collect(Collectors.joining(StrUtil.SPACE));
        return StrUtil.format("[{}] player show cards: [{}], remaining cards: ({}), please next player [{}] to play~", this.nickname, str, cardsCount, nextPlayerNickname);
    }

    public String showPlayHistory() {
        String str = CollUtil.isEmpty(this.cardList) ? "PASS" : this.cardList.stream().map(item -> StrUtil.equals("0", item) ? "10" : item.toUpperCase(Locale.ROOT)).collect(Collectors.joining(StrUtil.SPACE));
        return StrUtil.format("player [{}] show cards: [{}]", nickname, str);
    }

}
